import { onMounted, ref, computed, watchEffect, reactive } from "vue";
import { clone, delay } from "@pureadmin/utils";
import type { PaginationProps, LoadingConfig, Align } from "@pureadmin/table";
import { getAsyncsplx, getAsyncunits } from "@/api/searchFormOption";
import { getAsyncywxxtjs } from "@/api/yw";

// 业务信息统计api传递参数
// 员工id、页码、审批大类、审批子类、单位、审批主题（字符）、开始时间、结束时间
// employee_id、page、spdl、spzl、unit、spzt、start、end
export function useColumns() {
  const page = ref(1);
  const splx = ref(["全部", "全部"]);
  const unit = ref("全部");
  const spzt = ref(""); // Today's date in YYYY-MM-DD format
  const time_range = ref([
    "2024-01-01",
    new Date().toISOString().split("T")[0]
  ]);
  const total_num = ref(20);
  /** 分页配置 */
  const pagination = reactive<PaginationProps>({
    pageSize: 10,
    currentPage: 1,
    pageSizes: [10, 15, 20],
    total: 0,
    align: "right",
    background: true
  });

  /** 加载动画配置 */
  const loadingConfig = reactive<LoadingConfig>({
    text: "正在加载第一页...",
    viewBox: "-10, -10, 50, 50",
    spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    // svg: "",
    // background: rgba()
  });
  // 审批类型的选项
  const splx_values = ref([]);
  // 所有单位
  const units_values = ref([]);
  const tableDataMore = ref([]);

  onMounted(async () => {
    const splx_result = await getAsyncsplx();
    splx_values.value = splx_result.data;
    const units_result = await getAsyncunits();
    units_values.value = units_result.data;
    try {
      const res = await getAsyncywxxtjs({});
      console.log(
        "%c审批数据===>>>: ",
        "color: MidnightBlue; background: Aquamarine; font-size: 20px;",
        res
      );
      if (res.success) {
        tableDataMore.value = res.data;
        total_num.value = res.data[0].MAXRN;
      }
    } catch (error) {
      console.error("获取审批数据失败:", error);
    }
  });

  return {
    page,
    splx,
    unit,
    spzt,
    time_range,
    pagination,
    loadingConfig,
    splx_values,
    units_values,
    tableDataMore,
    total_num,
    getAsyncywxxtjs
  };
}
